import { defineConfig ,loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url';

import path from 'path-browserify'

let _resolve = (dir) => {
  return path.resolve(dir)
}
console.log(_resolve('src'))
export default ({mode})=>{
  // console.log(loadEnv,"loadEnv");
  let env = loadEnv(mode,process.cwd())

  
  return defineConfig({
    plugins: [vue()],
  // base: env.VITE_API_URL || '/',
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.vue'],
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
    javascriptEnabled: true
  },
  
  server: {
    proxy: {
      // 所有以 /api 开头的请求都代理到 http://localhost:8080
      '/api': {
        target: env.VITE_API_URL,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '') // 移除路径中的 /api 前缀
        
      },
    }
  },
 


  css: {
    preprocessorOptions: {
      scss: {
        // 全局注入变量文件，所有组件可直接使用变量
        additionalData: `@use "@/style/index.scss" as *;`
        // 注意：路径要和你的文件位置一致，若在 src/styles 目录则写 "@/styles/variables.scss"
      }
    }
  }
})
}
// defineConfig({
  
// })
